//
//  JKAccountManager.m
//  ZhiHuDaily
//
//  Created by albert on 16/9/4.
//  Copyright © 2016年 albert. All rights reserved.
//

#import "JKAccountManager.h"

@implementation JKAccountManager
{
    NSString *_userName;
    BOOL _isLogin;
}

JKSingletonM(manager)

+ (BOOL)loginWithUserName:(NSString *)userName password:(NSString *)password{
    // 在这里处理帐号和密码。暂时只要输入就登录吧
    if (userName == nil || password == nil) return NO;
    
    [[NSUserDefaults standardUserDefaults] setObject:userName forKey:JKUserNameKey];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
    [[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:JKIsLoginKey];
    [[NSUserDefaults standardUserDefaults] synchronize];
    return YES;
}

- (NSString *)userName{
    return self.isLogin ? _userName : @"未登录";
}

- (BOOL)isLogin{
    return [[NSUserDefaults standardUserDefaults] boolForKey:JKIsLoginKey];
}

+ (void)logout{
    [[NSUserDefaults standardUserDefaults] setObject:@"未登录" forKey:JKUserNameKey];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
    [[NSUserDefaults standardUserDefaults] setObject:@(NO) forKey:JKIsLoginKey];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
@end
